import pickle
import time

begining_of_events = time.time()

def mark_begining():
	global begining_of_events
	begining_of_events = time.time()

def get_time_stamp():
	global begining_of_events
	return time.time() - begining_of_events

class History:
	def __init__(self, logname):
		self.logname = logname
		self.data = []
	
	def write(self, element):
		if isinstance(element, tuple):
			self.data.append( (get_time_stamp(), ) + element )
		else:
			self.data.append( (get_time_stamp(), element, ) )
	
	def dump(self):
		now = time.strftime('%m-%d-%H%M')
		extension_ = self.logname + '_%s.pickle' % (now, )
		print 'extension is: ' + extension_
		f = open(extension_, 'wb')
		pickle.dump(self, f)



class MovementRecord:
	def __init__(self, motor_command='', diff_angle=None, pos_vector=None, my_angle=None, velocity_vector=None, distance_left=None):
		self.motor_command = motor_command
		self.diff_angle = diff_angle
		self.pos_vector = pos_vector
		self.my_angle = my_angle
		self.velocity_vector = velocity_vector
		self.distance_left = distance_left

	def __str__(self):
		return 'command: %s  angle: %s(%s) pos: %s  vel: %s  dis: %s' % \
			(self.motor_command, self.my_angle, self.diff_angle, self.pos_vector, self.velocity_vector, self.distance_left, )

	__repr__ = __str__

class BrainRecord:
	def __init__(self):
		pass 

	def __str__(self):
		pass 
	__repr__ = __str__



